home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Dev / misc / temgen.lha / Temgen / tg-0.11 / break.c < prev    next >
C/C++ Source or Header  |  2002-12-18  |  811b  |  42 lines

  1. #include "alloc.h"
  2. #include "generator.h"
  3. #include "sysdefs.h"
  4.  
  5. static int *brk_stack = NULL;
  6. static int  brk_size = 0;
  7. static int  brk_n = 0;
  8.  
  9. #define      DELTA   64
  10.  
  11. static void brk_fatal( void )
  12. {
  13.     fatal( "stack memory allocation error" );
  14. }
  15.  
  16. void   brk_push( int line )
  17. {
  18.     if ( !brk_stack ) {
  19.         brk_stack = (int*)MALLOC( DELTA * sizeof(brk_stack[0]) );
  20.         if ( !brk_stack ) brk_fatal();
  21.         brk_size = DELTA;
  22.         brk_n = 0;
  23.     }
  24.     
  25.     if ( brk_n >= brk_size ) {
  26.         brk_stack = (int*)REALLOC( brk_stack, 
  27.                 (brk_size + DELTA) * sizeof(brk_stack[0]) );
  28.         if ( !brk_stack ) brk_fatal();
  29.         brk_size += DELTA;
  30.     }
  31.    
  32.     brk_stack[ brk_n++ ] = line;
  33. }
  34.  
  35. int    brk_pop( void )
  36. {
  37.     if ( brk_n <= 0 ) return -1;
  38.     return brk_stack[ --brk_n ];
  39. }
  40.  
  41.  
  42.